#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=1e5+5;
int n,m,L,V;
int d[N],v[N],a[N],p[N];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int T;cin>>T;
    while(T--){
        cin>>n>>m>>L>>V;
        int ans=0;
        for(int i=1;i<=n;i++){
            cin>>d[i]>>v[i]>>a[i];
        }
        for(int i=1;i<=m;i++){
            cin>>p[i];
        }
        for(int i=1;i<=n;i++){
            if(v[i]>V&&d[i]<=p[m])ans++;
        }
        cout<<ans<<" ";
        if(ans==0)cout<<m<<"\n";
        else cout<<m-1<<"\n";
    }
    return 0;
}
